package com.mg.admin.bean;

import com.alibaba.fastjson.annotation.JSONField;
import org.apache.commons.lang3.builder.RecursiveToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

import java.io.Serializable;
import java.util.Date;

/**
 * BaseVO，所有返回给客户端的对象必须继承这个类
 */
public abstract class BaseVO implements Serializable {
    private static final long serialVersionUID = -5136660189516600399L;

    private Long id;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date gmtCreate;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date gmtModify;

    private Integer start; //分页开始位置

    private Integer length;  //每页条数


    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public Date getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(Date gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public Date getGmtModify() {
        return gmtModify;
    }

    public void setGmtModify(Date gmtModify) {
        this.gmtModify = gmtModify;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (obj == null) {
			return false;
		}

		if (null == this.getId()) {
			throw new UnsupportedOperationException("vo id is null");
		}

		if (getClass() != obj.getClass()) {
			return false;
		}

		BaseVO other = (BaseVO) obj;
		if (null == other.getId()) {
			throw new UnsupportedOperationException("vo id is null");
		}

		if (this.getId().equals(other.getId())) {
			return true;
		} else {
			return false;
		}
	}

    @Override
    public String toString() {
        return new ReflectionToStringBuilder(this, new RecursiveToStringStyle()).toString();
    }
}
